package leedcode_path.treeNoDE;

import java.util.LinkedList;
import java.util.Queue;

public class 完全二叉树的节点个数 {
    /**/
    public int countNodes(TreeNode root) {
        if (root==null) return 0;
        Queue<TreeNode> que=new LinkedList<TreeNode>();
        que.offer(root);
        int sum=0;
        while (!que.isEmpty()) {
            int len=que.size();
            while (len>0){
                TreeNode tem=que.poll();
                if (tem.left!=null) que.offer(tem.left);
                if (tem.right!=null) que.offer(tem.right);
                len--;
                sum++;
            }
        }
return sum;
    }
}
